package cool.taomu.toolkit.service.centre.kademlia.module

import com.google.inject.AbstractModule
import com.google.inject.TypeLiteral
import com.google.inject.name.Names
import cool.taomu.toolkit.rpc.thrift.provider.TTransportPoolProvider
import cool.taomu.toolkit.service.centre.kademlia.utils.ServiceCentreClientPool
import cool.taomu.toolkit.service.kademlia.provider.KBucketsModule
import org.apache.commons.pool2.impl.GenericObjectPoolConfig
import org.apache.thrift.transport.TTransport

class ServiceCentreModule extends AbstractModule {

    override configure() {
        var pool = new TypeLiteral<GenericObjectPoolConfig<TTransport>>() {
        };
        bind(pool).annotatedWith(Names.named("taomu.kademlia.pool.config")).toProvider(TTransportPoolProvider).
            asEagerSingleton;
        bind(ServiceCentreClientPool).asEagerSingleton
        install(new KBucketsModule)
    }
}
